﻿namespace Digitalmes.Core.Common.Interfaces;

/// <summary>
/// 消息队列
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IMessageQueue<T>
{
    /// <summary>
    /// 将事件写入队列。
    /// </summary>
    /// <param name="item">加入队列的事件项</param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    ValueTask EnqueueAsync(T item, CancellationToken cancellationToken = default);

    /// <summary>
    /// 异步读取，若队列中没有数据项时会异步阻塞当前线程。
    /// </summary>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    ValueTask<T> DequeueAsync(CancellationToken cancellationToken = default);
}
